/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.thienloc.omap.controller.soccer;

import com.thienloc.omap.controller.AbstractCrudBean;
import com.thienloc.omap.entity.GiaiDau;
import com.thienloc.omap.session.GiaiDauFacade;
import com.thienloc.omap.util.JsfUtil;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

/**
 *
 * @author GiangLT
 */
@ManagedBean
@ViewScoped
public class GiaiDauBean extends AbstractCrudBean {

    @EJB
    private GiaiDauFacade facade;
    private GiaiDau selected;
    private List<GiaiDau> list;

    @Override
    protected Logger getLogger() {
        return LoggerFactory.getLogger(GiaiDauBean.class);
    }

    @Override
    protected void resetToCreateFormAction() throws Exception {
        list = facade.findAll();
        selected = new GiaiDau();
        edit = false;
    }

    @Override
    protected void findSelected(int id) throws Exception {
        selected = facade.find(id);
    }

    @Override
    protected void createSelected() throws Exception {
        facade.create(selected);
        resetToCreateForm();
        JsfUtil.addSuccessMessage("Thành công!", "Đã thêm mới thành công một bản ghi");
    }

    @Override
    protected void editSelected() throws Exception {
        facade.edit(selected);
        resetToCreateForm();
        JsfUtil.addSuccessMessage("Thành công!", "Đã cập nhật thành công một bản ghi");
    }

    @Override
    protected void removeSelected() throws Exception {
        Integer id = Integer.parseInt(JsfUtil.getRequestParameter("id"));
        selected = facade.find(id);
        facade.remove(selected);
        resetToCreateForm();
        JsfUtil.addSuccessMessage("Thành công!", "Đã xóa thành công một bản ghi");
    }

    @Override
    protected void prepareViewAction() throws Exception {
    }

    @Override
    protected void prepareEditAction() throws Exception {
        edit = true;
        Integer id = Integer.parseInt(JsfUtil.getRequestParameter("id"));
        selected = facade.find(id);
    }

    @Override
    protected void validateForm() throws Exception {
    }

    public List<GiaiDau> getList() {
        return list;
    }

    public void setList(List<GiaiDau> list) {
        this.list = list;
    }

    public GiaiDau getSelected() {
        return selected;
    }

    public void setSelected(GiaiDau selected) {
        this.selected = selected;
    }
}
